home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
58189
/
58189.xpi
/
modules
/
Logger.jsm
< prev
next >
Wrap
Text File
|
2010-01-08
|
3KB
|
103 lines
/*
* The Logger supports logging operations. Messages have different severity types,
* which can be used to filter the output based on the log level.
*/
var EXPORTED_SYMBOLS = [ ];
Components.utils.import("resource://csfiremodules/CsFireCommon.jsm");
CsFire.Logger = new function() {
this.SEVERITY_DEBUG = 0;
this.SEVERITY_TEST = 1; //Before debug, so we can disable dirty debug output during test runs
this.SEVERITY_INFO = 2;
this.SEVERITY_WARN = 3;
this.SEVERITY_ERROR = 4;
this.SEVERITY_NAMES = {};
this.SEVERITY_NAMES[this.SEVERITY_TEST] = "TEST";
this.SEVERITY_NAMES[this.SEVERITY_DEBUG] = "DEBUG";
this.SEVERITY_NAMES[this.SEVERITY_INFO] = "INFO ";
this.SEVERITY_NAMES[this.SEVERITY_WARN] = "WARN ";
this.SEVERITY_NAMES[this.SEVERITY_ERROR] = "ERROR";
this.LOG_LEVEL = this.SEVERITY_INFO;
};
/*
* Logs a message with severity "TEST". This method can be called by other modules
* and is especially useful for output from test cases
*/
CsFire.Logger.test = function(message) {
this._log(message, this.SEVERITY_TEST);
};
/*
* Logs a message with severity "DEBUG". This method can be called by other modules.
*/
CsFire.Logger.debug = function(message) {
this._log(message, this.SEVERITY_DEBUG);
};
/*
* Logs a message with severity "INFO". This method can be called by other modules.
*/
CsFire.Logger.info = function(message) {
this._log(message, this.SEVERITY_INFO);
};
/*
* Logs a message with severity "WARN". This method can be called by other modules.
*/
CsFire.Logger.warn = function(message) {
this._log(message, this.SEVERITY_WARN);
};
/*
* Logs a message with severity "ERROR". This method can be called by other modules.
*/
CsFire.Logger.error = function(message) {
this._log(message, this.SEVERITY_ERROR);
};
/*
* Log a message with the associated severity. This function constructs the final
* message that will be logged. The output channel is determined here by which
* function is called to actually log the message.
*
* This function is meant for internal use only.
*/
CsFire.Logger._log = function(message, severity) {
if(this.LOG_LEVEL <= severity) {
var text = "[" + this._getTimeStamp() + "][CsFire][" + this.SEVERITY_NAMES[severity] + "][ " + message + "]\n";
this._logToSystemConsole(text);
}
};
/*
* Return a timestamp to include in a log entry
*/
CsFire.Logger._getTimeStamp = function() {
function fill(n) {
if(n < 10) {
return "0" + n;
}
else {
return n;
}
}
var now = new Date();
return fill(now.getDate()) + "/" + fill(now.getMonth() + 1) + "/" + now.getFullYear() + " " + fill(now.getHours()) + ":" + fill(now.getMinutes()) + ":" + fill(now.getSeconds());
}
/*
* Logs a message to the system console, which is a terminal on the Linux OS or the
* Firefox console on Windows (firefox.exe -console).
*
* This function is meant for internal use only.
*/
CsFire.Logger._logToSystemConsole = function(text) {
dump(text);
};